package com.itheima.controller;

import com.itheima.dto.RecommendProduct;
import com.itheima.dto.RecommendSubject;
import com.itheima.service.SmsHomeRecommendProductService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/recommendProduct")
public class SmsHomeRecommendProductController {
    @Autowired
    private SmsHomeRecommendProductService smsHomeRecommendProductService;


    /**
     * 创建首页推荐
     *
     * @return
     */
    @PostMapping("create")
    public ResponseEntity create(@RequestBody List<RecommendProduct> recommendProduct) {
        smsHomeRecommendProductService.createProduct(recommendProduct);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 批量删除首页推荐专题
     * @param
     * @return
     */
    @PostMapping("delete")
    public ResponseEntity delete(Integer[] ids) {
        smsHomeRecommendProductService.delete(ids);
        return ResponseEntity.ok(Result.success(null));
    }


    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param recommendStatus
     * @param subjectName
     * @return
     */
    @GetMapping("list")
    public ResponseEntity findAllPages(@RequestParam(defaultValue = "1") Integer pageNum ,
                                       @RequestParam(defaultValue = "2") Integer pageSize,
                                       Integer recommendStatus,
                                       String subjectName) {
        PageResultVo<RecommendProduct> prv=smsHomeRecommendProductService.list(pageNum,pageSize,recommendStatus,subjectName);
        return ResponseEntity.ok(Result.success(prv));
    }


    /**
     * 根据 传来的id数组 以及状态 批量修改主专题状态
     * @param recommendStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity update(@RequestParam Integer recommendStatus , Integer[] ids) {
        smsHomeRecommendProductService.update(recommendStatus,ids);
        return ResponseEntity.ok(Result.success(null));
    }

    /**
     * 修改排序值
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity updateSort(@PathVariable("id") Integer id,Integer sort) {
        smsHomeRecommendProductService.updateSort(id,sort);
        return ResponseEntity.ok(Result.success(null));
    }





}
